/** Copyright (c) 2010 BullionXpress.com,
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * @author BullionXpress.com
 *
 */
package com.bullionxpress.shared.application;

import com.bullionxpress.client.application.Client;
import javax.swing.SwingUtilities;
import com.bullionxpress.client.view.DockingFrame;
import com.bullionxpress.server.application.Server;

/**
 */
public class Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        System.out.println("Application Starting...");
        String startup = "";
        if (args.length < 1) {
            startup = "-client";
        } else {
            startup = args[0];
        }

        if (startup.equals("-client")) {
            System.out.println("Initializing Client...");

            Client client = new Client();
            client.connect();

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    DockingFrame df = new DockingFrame();
                    df.initializeAndRun();
                }
            });


        } else if (startup.equals("-server")) {
            System.out.println("Initializing Server...");
            Server server = new Server();
        } else if (startup.equals("-?")) {
            System.out.println("java -jar bullionxpress.jar -client [or -server]");
            System.out.println("-client: Run the client");
            System.out.println("-server: Run the server");
            System.out.println("default (no argument): Run the client");
            
            Application.quit();
        } else {
            System.out.println("Unknown startup parameter:" + startup);
            Application.quit();
        }
    }

    public static void quit() {
        System.out.println("QUITTING...");
        System.exit(-1);
    }
}
